package com.ruoyi.roadcard.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.roadcard.domain.RoadCard;
import com.ruoyi.roadcard.service.IRoadCardService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 行程码查询Controller
 *
 * @author 刘焕然
 * @date 2022-12-09
 */
@RestController
@RequestMapping("/roadcard/card")
public class RoadCardController extends BaseController
{
    @Autowired
    private IRoadCardService roadCardService;

    /**
     * 查询行程码查询列表
     */
    @PreAuthorize("@ss.hasPermi('roadcard:card:list')")
    @GetMapping("/list")
    public TableDataInfo list(RoadCard roadCard)
    {
        startPage();
        List<RoadCard> list = roadCardService.selectRoadCardList(roadCard);
        return getDataTable(list);
    }

    /**
     * 导出行程码查询列表
     */
    @PreAuthorize("@ss.hasPermi('roadcard:card:export')")
    @Log(title = "行程码查询", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RoadCard roadCard)
    {
        List<RoadCard> list = roadCardService.selectRoadCardList(roadCard);
        ExcelUtil<RoadCard> util = new ExcelUtil<RoadCard>(RoadCard.class);
        util.exportExcel(response, list, "行程码查询数据");
    }

    /**
     * 获取行程码查询详细信息
     */
    @PreAuthorize("@ss.hasPermi('roadcard:card:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(roadCardService.selectRoadCardById(id));
    }

    /**
     * 新增行程码查询
     */
    @PreAuthorize("@ss.hasPermi('roadcard:card:add')")
    @Log(title = "行程码查询", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RoadCard roadCard)
    {
        return toAjax(roadCardService.insertRoadCard(roadCard));
    }

    /**
     * 修改行程码查询
     */
    @PreAuthorize("@ss.hasPermi('roadcard:card:edit')")
    @Log(title = "行程码查询", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RoadCard roadCard)
    {
        return toAjax(roadCardService.updateRoadCard(roadCard));
    }

    /**
     * 删除行程码查询
     */
 /*   @PreAuthorize("@ss.hasPermi('roadcard:card:remove')")
    @Log(title = "行程码查询", businessType = BusinessType.DELETE)
	@DeleteMapping("/{idCards}")
    public AjaxResult remove(@PathVariable String[] idCards)
    {
        return toAjax(roadCardService.deleteRoadCardByIdCards(idCards));
    }*/

    /**
     * 删除行程码查询
     */
    @PreAuthorize("@ss.hasPermi('roadcard:card:remove')")
    @Log(title = "行程码查询", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(roadCardService.deleteRoadCardByIds(ids));
    }
}
